const fs = require("fs");
const path = require("path");
const express = require("express");
const app = express();
const server = require("http").createServer(app);
const compression = require("compression");

const {port} = require("../build/config");


app.engine("html", function (filePath,options,callback){
    fs.readFile(filePath, function (error, content) {
        if (error) {
            return callback(error);
        }
        return callback(null, content.toString());
    });
});
app.set("views", path.join(__dirname, "../dist"));
app.set("view engine", "html");
app.use(compression());
app.use("/static",express.static(path.join(__dirname, "../dist/static")));
app.use("/api",require("../serve/index"));


app.use("/admin**",(req, res) =>{
    res.set("content-type", "text/html");
    res.render("admin");
});

app.use("/**",(req, res) =>{
    res.set("content-type", "text/html");
    res.render("client");
});


server.listen(port,function (){
    console.log(`app listening on port ${port}!`);
});
